package com.zykj.hystrix.controller;

import com.netflix.discovery.converters.Auto;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.zykj.hystrix.service.HystrixService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.client.circuitbreaker.EnableCircuitBreaker;
import org.springframework.cloud.netflix.hystrix.dashboard.EnableHystrixDashboard;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


/**
 * @author zhoulj(周利军) [1217102780@qq.com]
 * @Title: HystrixController
 * @Project: ${MODEL_NAME}
 * @Module ID:   <(模块)类编号，可以引用系统设计中的类编号>
 * @Comments: <对此类的描述，可以引用系统设计中的描述>
 * @JDK version used:      <JDK1.8> 16
 * @since 2018/12/22-14:16
 */
@RestController
@RequestMapping("hystrix11")
@EnableHystrixDashboard
@EnableCircuitBreaker
public class HystrixController {

    Logger logger = LoggerFactory.getLogger(HystrixController.class);
    @Autowired
    HystrixService hystrixService;
    @RequestMapping
    @HystrixCommand(fallbackMethod = "hiError")
    public String hystrixIndex(String name) {
        logger.debug("【HystrixController》hystrixIndex 方法进入...】");
        return hystrixService.getService(name + "当前端口：" + 8080);

    }

    public String hiError(String name) {
        return "hi,"+name+",sorry,error!";
    }
}
